package com.daka.tools;

import com.daka.entity.Activity;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author beliveli
 *         Get information from config file
 */

public class ConfigUtil {

    public static final String CLIENT_ID = "1003";
    public static final Integer BATCH_INSERT_MAX = 1000;

    public static Integer selectMax = 0;
    public static Integer selectMin = 0;
    public static Integer tempMobile = 0;

    public static void buildConfig() {

        /**
         * 如果已经生成过 就不再重复生成
         */
        if (selectMax == 0 && selectMin == 0 && tempMobile == 0) {

            Properties properties = new Properties();
            InputStream inputStream;
            try {
                Activity a = new Activity();
                String path = a.getClass().getResource("/").getFile() + "/data.properties";
                inputStream = new FileInputStream(path);
                properties.load(inputStream);

                Integer selectMaxTemp = Integer.parseInt(properties.getProperty("select.max"));
                Integer selectMinTemp = Integer.parseInt(properties.getProperty("select.min"));
                Integer selectMobileTemp = Integer.parseInt(properties.getProperty("temp.mobile"));

                ConfigUtil.selectMax = selectMaxTemp;
                ConfigUtil.selectMin = selectMinTemp;
                ConfigUtil.tempMobile = selectMobileTemp;
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }


    }

}
